/**
 * 本质上，表单就是 POST 方法发送到服务器的键值对
 * */
const koaBody = require('koa-body') ;
const Koa = require('koa');
const app = new Koa();

const main = async ctx => {
    const body = ctx.request.body;
    if(!body.name) ctx.throw(400, 'name required');
    ctx.body = { name: body.name };
};

app.use(koaBody());
app.use(main);
app.listen(3006);

